{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "label_m = pd.read_csv('../date/label-month.csv',header=None)\n",
    "label_d = pd.read_csv('../date/label-day.csv',header=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "label_m = label_m.values.reshape(-1)\n",
    "label_d = label_d.values.reshape(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "valid_date= pd.read_csv('../../preprocess_data/valid_date.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "# date_weight = valid_date.apply(lambda row: label_d[row['loan_day']-1]*label_m[row['loan_month']-1],axis =1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "date_weight = valid_date.apply(lambda row: label_m[row['loan_month']-1],axis =1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['xgb17.csv', 'xgb35.csv', 'xgb11.csv', 'xgb12.csv', 'xgb8.csv', 'xgb33.csv', 'xgb3.csv', 'xgb6.csv', 'xgb18.csv', 'xgb14.csv', 'xgb25.csv', 'xgb4.csv', 'xgb29.csv', 'xgb9.csv', 'xgb27.csv', 'xgb13.csv', 'xgb31.csv', 'xgb20.csv', 'xgb0.csv', 'xgb24.csv', 'xgb19.csv', 'xgb26.csv', 'xgb2.csv', 'xgb23.csv', 'xgb5.csv', 'xgb32.csv', 'xgb21.csv', 'xgb1.csv', 'xgb34.csv', 'xgb15.csv', 'xgb7.csv', 'xgb10.csv', 'xgb22.csv', 'xgb30.csv', 'xgb28.csv', 'xgb16.csv']\n"
     ]
    }
   ],
   "source": [
    "files = os.listdir('./preds')\n",
    "print(files)\n",
    "pred = pd.read_csv('./preds/'+files[0])\n",
    "id = pred.id\n",
    "score = pred.score.rank()\n",
    "for f in files[1:]:\n",
    "    pred = pd.read_csv('./preds/'+f)\n",
    "    score += pred.score.rank()\n",
    "\n",
    "w_score = score*date_weight\n",
    "\n",
    "pred = pd.DataFrame(id,columns=['id'])\n",
    "pred['prob'] = w_score\n",
    "pred.to_csv('avg_preds_date_weight.csv',index=None,encoding='utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        0.063256\n",
       "1        0.063256\n",
       "2        0.064643\n",
       "3        0.063256\n",
       "4        0.064643\n",
       "5        0.063256\n",
       "6        0.063256\n",
       "7        0.064643\n",
       "8        0.078993\n",
       "9        0.063256\n",
       "10       0.063256\n",
       "11       0.064643\n",
       "12       0.063256\n",
       "13       0.078993\n",
       "14       0.078993\n",
       "15       0.078993\n",
       "16       0.064643\n",
       "17       0.064643\n",
       "18       0.063256\n",
       "19       0.064643\n",
       "20       0.078993\n",
       "21       0.063256\n",
       "22       0.078993\n",
       "23       0.047087\n",
       "24       0.063256\n",
       "25       0.064643\n",
       "26       0.047087\n",
       "27       0.047087\n",
       "28       0.064643\n",
       "29       0.047087\n",
       "           ...   \n",
       "19970    0.078993\n",
       "19971    0.064643\n",
       "19972    0.047087\n",
       "19973    0.063256\n",
       "19974    0.047087\n",
       "19975    0.063256\n",
       "19976    0.078993\n",
       "19977    0.064643\n",
       "19978    0.047087\n",
       "19979    0.064643\n",
       "19980    0.064643\n",
       "19981    0.063256\n",
       "19982    0.063256\n",
       "19983    0.078993\n",
       "19984    0.078993\n",
       "19985    0.063256\n",
       "19986    0.047087\n",
       "19987    0.078993\n",
       "19988    0.063256\n",
       "19989    0.064643\n",
       "19990    0.078261\n",
       "19991    0.047087\n",
       "19992    0.078993\n",
       "19993    0.063256\n",
       "19994    0.063256\n",
       "19995    0.078993\n",
       "19996    0.064643\n",
       "19997    0.078993\n",
       "19998    0.063256\n",
       "19999    0.064643\n",
       "Length: 20000, dtype: float64"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_weight"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
